package com.xiaoyu.lanling.feature.visitor

import android.os.Bundle
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.activity.base.AppCompatToolbarActivity
import com.xiaoyu.lanling.common.Constant
import com.xiaoyu.lanling.event.user.VisitorReadEvent
import com.xiaoyu.lanling.feature.visitor.fragment.FootprintFragment
import com.xiaoyu.lanling.feature.visitor.fragment.VisitorFragment
import com.xiaoyu.lanling.view.FragmentAdapter
import com.xiaoyu.lanling.view.OnShowFragment
import com.xiaoyu.lanling.widget.tablayout.ScaleTabLayoutUtils
import kotlinx.android.synthetic.main.activity_visitor_history.*

class VisitorHistoryActivity : AppCompatToolbarActivity() {

    override fun onCreateSafelyAfterAppFinishInit(savedInstanceState: Bundle?) {
        super.onCreateSafelyAfterAppFinishInit(savedInstanceState)
        setLightStatusBar()
        setContentView(R.layout.activity_visitor_history)
        initToolbar()

        initView()
        VisitorReadEvent().post()
    }

    private fun initView() {
        title = getString(R.string.visitor_mine)
        initViewPager()
    }

    private fun initViewPager() {
        val titles = listOf(getString(R.string.visitor_tab_title), getString(R.string.visitor_footprint_tab_title))
        val fragmentList = mutableListOf<OnShowFragment>()

        ScaleTabLayoutUtils.createAccentVisitorScaleTabLayout(toolbar_tab_layout, view_pager, titles, true)

        val visitorCount: Int = intent.getIntExtra(Constant.IntentKey.KEY_VISITOR_COUNT, 0)
        fragmentList.add(VisitorFragment.newInstance(visitorCount))
        fragmentList.add(FootprintFragment())
        val fragmentAdapter = FragmentAdapter(supportFragmentManager, fragmentList, titles)
        view_pager.offscreenPageLimit = fragmentList.size
        view_pager.adapter = fragmentAdapter
    }
}